package com.fernandomartines.dbcheck.app.model;

import java.util.Hashtable;
import javax.swing.table.DefaultTableModel;

public class TestCaseTableModel extends DefaultTableModel {

    private Hashtable lookup;
    private final int rows;
    private final int columns;
    private final String headers[];

    public TestCaseTableModel(int rows, String columnHeaders[]) {
        if ((rows < 0) || (columnHeaders == null)) {
            throw new IllegalArgumentException(
                    "Invalid row count/columnHeaders");
        }
        this.rows = rows;
        this.columns = columnHeaders.length;
        headers = columnHeaders;
        lookup = new Hashtable();
    }

    @Override
    public boolean isCellEditable(int row, int col) {
        return false;
    }

    @Override
    public String getColumnName(int col) {
        return headers[col];
    }

    @Override
    public int getRowCount() {
        return rows;
    }

    @Override
    public int getColumnCount() {
        return columns;
    }

    @Override
    public Object getValueAt(int row, int col) {
        return lookup.get("R" + row + "C" + col);
    }

    @Override
    public void setValueAt(Object value, int row, int col) {
        if ((rows < 0) || (columns < 0)) {
            throw new IllegalArgumentException("Invalid row/column setting");
        }
        if ((row < rows) && (col < columns)) {
            lookup.put("R" + row + "C" + col, value);
        }
    }

}
